import { UserAction } from "./userActions"

export interface UserRawState {
  username: string,
  nickname: string,
  avator: string,
  role: string,
  token: string
}

const initState: UserRawState = {
  username: '',
  nickname: '',
  avator: '',
  role: '',
  token: ''
}




const userReducer = (state = initState, action: UserAction): UserRawState => {
  switch (action.type) {
    case 'LOGIN_QUIT': {
      return {
        username: '',
        nickname: '',
        avator: '',
        role: '',
        token: ''
      }
      break;
    }
    case 'LOGIN_SUCCESS': {
      return {
        ...action.payload
      }
      break
    }
    default: return state
  }
}


export default userReducer